package com.three.Controller;

import com.github.pagehelper.PageInfo;
import com.three.Pojo.Classes;
import com.three.Service.IClassService;
import org.apache.ibatis.plugin.Interceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/class")
public class ClassController {
    @Autowired
    private IClassService classService;

    @RequestMapping("/toclass.do")
    public  String toclass(ModelMap map, String className,
                           @RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "5") Integer pageSize){
        PageInfo<Classes> pagelist=classService.findlist(pageNum,pageSize,className);
        map.addAttribute("pagelist",pagelist);
        map.addAttribute("className",className);
        return "class";
    }
    @RequestMapping("/toadd.do")
    public String toadd(){
        return "classAdd";
    }
    @RequestMapping("/addsave.do")
    public String addsave(Classes clas){
        classService.addsave(clas);
        return "redirect:/class/toclass.do";
    }

    @RequestMapping("/promodify.do")
    public String promodify(ModelMap map,Integer Id){
        Classes clas=classService.findByid(Id);
        map.addAttribute("clas",clas);
        return "classUpdate";
    }
    @RequestMapping("/updatesave.do")
    public String updatesave(Classes clas){
        classService.updatesave(clas);
        return "redirect:/class/toclass.do";
    }
    @RequestMapping("/delete.do")
    public String delete(Integer Id){
        classService.delete(Id);
        return "redirect:/class/toclass.do";
    }

}
